<template>
  <button :zh-click-animating-without-extra-node="extra"  :class="buttonCls" @click="onClick">
    <span>
      <slot></slot>
    </span>
  </button>
</template>

<script>

  let typeMap = {
    primary: 'primary',
    danger: 'danger',
    dashed: 'dashed',
  }

  let sizeMap = {
  	large: 'lg',
    small: 'sm'
  }

  let shapeMap = {
    circle: 'circle',
    round: 'round'
  }

  export default{
    name: 'static-button',
    props: {
      type: {
        type: String,
        default: 'primary'
      },
      shape: {
        type: String,
        default: ''
      },
      disabled: {
        type: Boolean,
        default: false
      },
      size: {
        type: String,
        default: ''
      },
      loading: {
        type: Boolean,
        default: false
      }
    },
    data(){
    	let sizeCls = ''
      if(this.size!=='undefined')
        sizeCls = 'zh-btn-'+ sizeMap[this.size];
      let buttonCls = ['zh-btn'];
      buttonCls.push(sizeCls);

      let shapeCls = ''
      if(this.shape){
        shapeCls = 'zh-btn-'+ shapeMap[this.shape];
      }
      buttonCls.push(shapeCls);

      let typeCls = ''
      if(this.type){
        typeCls = 'zh-btn-'+ typeMap[this.type];
      }
      buttonCls.push(typeCls);

      return {
        extra: false,
        buttonCls: buttonCls
      }
    },
    methods: {
      onClick(){
          this.extra = false;
          setTimeout(()=>{
            this.extra = true;
          },50)
        this.$emit('click', this);
      }
    }
  }
</script>

<style lang="less">
  @import "../../style/test.less";

  .zh-btn, .zh-btn:active, .zh-btn:focus {
    outline: 0;
  }


  [zh-click-animating-without-extra-node='true']::after, .zh-click-animating-node {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: block;
    border-radius: inherit;
    -webkit-box-shadow: 0 0 0 0 #1890ff;
    box-shadow: 0 0 0 0 #1890ff;
    opacity: .2;
    -webkit-animation: fadeEffect 2s cubic-bezier(.08, .82, .17, 1), waveEffect .4s cubic-bezier(.08, .82, .17, 1);
    animation: fadeEffect 2s cubic-bezier(.08, .82, .17, 1), waveEffect .4s cubic-bezier(.08, .82, .17, 1);
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
    content: '';
    pointer-events: none;
  }

  .zh-btn {
    line-height: 1.499;
    position: relative;
    display: inline-block;
    font-weight: 400;
    white-space: nowrap;
    text-align: center;
    background-image: none;
    border: 1px solid transparent;
    -webkit-box-shadow: 0 2px 0 rgba(0, 0, 0, 0.015);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.015);
    cursor: pointer;
    -webkit-transition: all .3s cubic-bezier(.645, .045, .355, 1);
    transition: all .3s cubic-bezier(.645, .045, .355, 1);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    height: 32px;
    padding: 0 15px;
    font-size: 14px;
    border-radius: 4px;
    color: rgba(0, 0, 0, 0.65);
    background-color: #fff;
    border-color: #d9d9d9;
  }

  .zh-btn::before {
    position: absolute;
    top: -1px;
    right: -1px;
    bottom: -1px;
    left: -1px;
    z-index: 1;
    display: none;
    background: #fff;
    border-radius: inherit;
    opacity: .35;
    -webkit-transition: opacity .2s;
    transition: opacity .2s;
    content: '';
    pointer-events: none;
  }

  .zh-btn-sm {
    height: 24px;
    padding: 0 7px;
    font-size: 14px;
    border-radius: 4px;
  }

  .zh-btn-lg {
    height: 40px;
    padding: 0 15px;
    font-size: 16px;
    border-radius: 4px;
  }
  .zh-btn>i, .zh-btn>span {
    display: inline-block;
    pointer-events: none;
  }

  .zh-btn-circle, .zh-btn-circle-outline {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 16px;
    border-radius: 50%;
  }

  .zh-btn-danger {
    color: #f5222d !important;
    background-color: #f5f5f5 !important;
    border-color: #d9d9d9 !important;
  }

  .zh-btn-danger:hover {
    color: #fff !important;
    background-color: #ff4d4f !important;
    border-color: #ff4d4f !important;
  }

  .zh-btn-danger:active, .zh-btn-danger.active {
    color: #fff !important;
    background-color: #cf1322 !important;
    border-color: #cf1322  !important;
  }

  .zh-btn-danger[zh-click-animating-without-extra-node='true']::after{
    -webkit-box-shadow: 0 0 0 0 #ff4d4f  !important;
    box-shadow: 0 0 0 0 #ff4d4f  !important;
  }

  .zh-btn-dashed {
    color: rgba(0,0,0,0.65);
    background-color: #fff;
    border-color: #d9d9d9;
    border-style: dashed;
  }

  .zh-btn-round {
    height: 32px;
    padding: 0 16px;
    font-size: 16px;
    border-radius: 32px;
  }

  .zh-btn-primary {
    color: #fff;
    background-color: #1890ff;
    border-color: #1890ff;
    text-shadow: 0 -1px 0 rgba(0,0,0,0.12);
    -webkit-box-shadow: 0 2px 0 rgba(0,0,0,0.045);
    box-shadow: 0 2px 0 rgba(0,0,0,0.045);
  }

  .zh-btn:active, .zh-btn.active {
    color: #096dd9;
    background-color: #fff;
    border-color: #096dd9;
  }

  .zh-btn:hover, .zh-btn:focus {
    color: #40a9ff;
    background-color: #fff;
    border-color: #40a9ff;
  }
</style>
